//
//  PlayCollectionViewCell.m
//  MyTrip
//
//  Created by dllo on 15/9/29.
//  Copyright (c) 2015年 张益. All rights reserved.
//

#import "PlayCollectionViewCell.h"
#import "PlayTableViewCell.h"
#import "ACollectionViewCell.h"
#import "BCollectionViewCell.h"
#import "CCollectionViewCell.h"
#import "DCollectionViewCell.h"
#import "ECollectionViewCell.h"
@interface PlayCollectionViewCell()<UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic , retain)UITableView *tabel;
@property (nonatomic , retain)NSArray *array;
@property (nonatomic , retain)UICollectionView *collview;
@end

@implementation PlayCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createrView];
    }
    return self;
}
-(void)createrView
{
        self.contentView.backgroundColor=[UIColor whiteColor];
    
        UIImageView *ima  = [[UIImageView alloc]initWithFrame:CGRectMake(0, 5,self.contentView.frame.size.width, 250)];
        ima.image=[UIImage imageNamed:@"trip.jpg"];
        [self.contentView addSubview:ima];
         self.array=[NSArray arrayWithObjects:@"美女",@"奇葩",@"萌宠",@"精品",@"趣味", nil];
    
         self.tabel = [[UITableView alloc]initWithFrame:CGRectMake(0, 260, 100, 450) style:UITableViewStyleGrouped ];
         self.tabel.dataSource = self;
         self.tabel.delegate = self;
         self.tabel.bounces = YES;
         self.tabel.backgroundColor=[UIColor clearColor];
         self.tabel.showsVerticalScrollIndicator = NO;
         [self.tabel registerClass:[PlayTableViewCell class] forCellReuseIdentifier:@"a"];
         [self.contentView addSubview:self.tabel];
    
    
         UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
         layout.itemSize = CGSizeMake(self.frame.size.width, 480);
         layout.minimumInteritemSpacing = 0;
         layout.minimumLineSpacing = 0;
         layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
         self.collview = [[UICollectionView alloc]initWithFrame:CGRectMake(105, 200, 300,600) collectionViewLayout:layout];
         self.collview.delegate = self;
         self.collview.dataSource = self;
         self.collview.pagingEnabled = YES;
         self.collview.contentSize=CGSizeMake(self.frame.size.width*5, 0);
         self.collview.backgroundColor=[UIColor clearColor];
         self.collview.scrollEnabled = NO;
         self.collview.bounces = YES;
    
    
         
         [self.collview registerClass:[ACollectionViewCell class] forCellWithReuseIdentifier:@"A"];
         [self.collview registerClass:[BCollectionViewCell class] forCellWithReuseIdentifier:@"B"];
         [self.collview registerClass:[CCollectionViewCell class] forCellWithReuseIdentifier:@"C"];
         [self.collview registerClass:[DCollectionViewCell class] forCellWithReuseIdentifier:@"D"];
         [self.collview registerClass:[ECollectionViewCell class] forCellWithReuseIdentifier:@"E"];
    
         [self.contentView addSubview:self.collview];
    
    
    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 125;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.array.count;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    PlayTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"a"];
    
    cell.label.text = [self.array objectAtIndex:indexPath.row];
    
    return cell;
    
    
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 5;
    
}
/**
 *  tabel点击事件
 *
 *  @param tableView
 *  @param indexPath
 */
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [self.tabel deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.row ==0) {
        self.collview.contentOffset = CGPointMake(0, 0);
    }
    if (indexPath.row ==1) {
        self.collview.contentOffset = CGPointMake(375, 0);
    }
    if (indexPath.row==2) {
        self.collview.contentOffset = CGPointMake(375*2, 0);
    }
    if (indexPath.row ==3) {
        self.collview.contentOffset = CGPointMake(375*3, 0);
    }
    if (indexPath.row ==4) {
        self.collview.contentOffset = CGPointMake(375*4, 0);
    }
    
    
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.item==0) {
         ACollectionViewCell *acell=[collectionView dequeueReusableCellWithReuseIdentifier:@"A" forIndexPath:indexPath];
        return acell;
    }
    if (indexPath.item==1) {
         BCollectionViewCell *bcell=[collectionView dequeueReusableCellWithReuseIdentifier:@"B" forIndexPath:indexPath];
        return bcell;
    }
    if (indexPath.item==2) {
          CCollectionViewCell *ccell=[collectionView dequeueReusableCellWithReuseIdentifier:@"C" forIndexPath:indexPath];
        return ccell;
    }
    if (indexPath.item==3) {
         DCollectionViewCell *dcell=[collectionView dequeueReusableCellWithReuseIdentifier:@"D" forIndexPath:indexPath];
        return dcell;
    }
    if (indexPath.item==4) {
        ECollectionViewCell *ecell=[collectionView dequeueReusableCellWithReuseIdentifier:@"E" forIndexPath:indexPath];
        return ecell;
    }
    
    return nil;
    
}






@end
